package cn.formaggie.service.impl;

import cn.formaggie.dao.PermissionDao;
import cn.formaggie.dao.RoleDao;
import cn.formaggie.dao.WorkerDao;
import cn.formaggie.entity.model.roleandpermission.Role;
import cn.formaggie.service.face.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("roleService")
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleDao roleDao;
    @Autowired
    private WorkerDao workerDao;
    @Autowired
    private PermissionDao permissionDao;

    @Override
    public Role getRoleById(Integer id) {
        return roleDao.getRoleById(id);
    }

    @Override
    public List<Role> findRoles(Map<String,Object> map) {
        return roleDao.findRoles(map);
    }

    @Override
    public List<Role> findAllRoles() {
        return roleDao.findAllRoles();
    }

    @Override
    public Integer getRolesCount(Map<String,Object> map) {
        return roleDao.getRolesCount(map);
    }

    @Override
    public Boolean addRole(Role role) {
        return roleDao.addRole(role)>0?true:false;
    }

    @Override
    public Boolean deleteRole(Integer id) {
       boolean hasRoleInWorkers=workerDao.hasRoleInWorkers(id);

       if(hasRoleInWorkers){
           return false;
       }else{
           return roleDao.deleteRole(id)>0?true:false;
       }


    }

    @Override
    public Boolean modifyRoleInfo(Role role) {
        return roleDao.modifyRoleInfo(role)>0?true:false;
    }
}
